import { createStore } from 'vuex';
import axios from 'axios';

const store = createStore({
  state: {
    categoryData: null,
  },
  mutations: {
    setCategoryData(state, data) {
      state.categoryData = data;
    },
  },
  actions: {
    async fetchCategoryData({ commit }) {
      try {
        const response = await tokenAxios.get('http://123.60.129.240:49282/categories/tree');
        if (response.state === 20000) {
          commit('setCategoryData', response.data);
        } else {
          // 处理其他状态码或错误情况  
        }
      } catch (error) {
        console.error('请求错误:', error);
      }
    },
  },
});

export default store;